Skip to content

fix: use atomic DTR/RTS reset on unix for CH340/UART bridges#37

Merged
deadprogram merged 1 commit intotinygo-org:mainfrom
jgangemi:jae/unix-tight-reset
Apr 24, 2026
Merged

fix: use atomic DTR/RTS reset on unix for CH340/UART bridges#37
deadprogram merged 1 commit intotinygo-org:mainfrom
jgangemi:jae/unix-tight-reset

Conversation

@jgangemi
Copy link
Copy Markdown
Contributor

go.bug.st/serial issues SetDTR and SetRTS as separate ioctls, which on
macOS with the CH340 VCP driver can drop or reorder the transitions and
leave the chip unable to enter download mode. esptool.py addresses this
with UnixTightReset, which uses a single TIOCMSET ioctl to change both
modem lines atomically.

  • add setDTRandRTS helper that prefers atomic TIOCMSET on darwin/linux
    and falls back to separate ioctls elsewhere
  • add unixTightReset matching esptool.py's sequence and delay constants
    (default 50ms, extra 550ms)
  • on darwin/linux, ResetDefault now cycles unixTightReset/classicReset
    across attempts like esptool.py's default-reset list; other platforms
    keep the prior behavior
  • on darwin/linux, ResetAuto now also includes unixTightReset in its
    dispatch cycle (unixTightReset, classicReset, USB-JTAG, unixTightReset
    extra delay, no-reset) so CH340 devices sync correctly under the
    default reset mode; non-unix platforms retain the prior 3-strategy
    cycle

go.bug.st/serial issues SetDTR and SetRTS as separate ioctls, which on
macOS with the CH340 VCP driver can drop or reorder the transitions and
leave the chip unable to enter download mode. esptool.py addresses this
with UnixTightReset, which uses a single TIOCMSET ioctl to change both
modem lines atomically.

- add setDTRandRTS helper that prefers atomic TIOCMSET on darwin/linux
  and falls back to separate ioctls elsewhere
- add unixTightReset matching esptool.py's sequence and delay constants
  (default 50ms, extra 550ms)
- on darwin/linux, ResetDefault now cycles unixTightReset/classicReset
  across attempts like esptool.py's default-reset list; other platforms
  keep the prior behavior
- on darwin/linux, ResetAuto now also includes unixTightReset in its
  dispatch cycle (unixTightReset, classicReset, USB-JTAG, unixTightReset
  extra delay, no-reset) so CH340 devices sync correctly under the
  default reset mode; non-unix platforms retain the prior 3-strategy
  cycle
@deadprogram
Copy link
Copy Markdown
Member

Tested on Ubuntu and working as expected. Thanks for the fix @jgangemi now merging.

@deadprogram deadprogram merged commit 5a91087 into tinygo-org:main Apr 24, 2026
3 checks passed
@jgangemi jgangemi deleted the jae/unix-tight-reset branch April 25, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants